﻿@* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True *@
@using System
@using DotNetCore.CAP.Dashboard
@using DotNetCore.CAP.Dashboard.Pages
@using DotNetCore.CAP.Dashboard.Resources
@using DotNetCore.CAP.Messages
@using DotNetCore.CAP.Monitoring
@inherits DotNetCore.CAP.Dashboard.RazorPage
@{
    Layout = new LayoutPage(Strings.PublishedMessagesPage_Title);

    int from, perPage;

    int.TryParse(Query("from"), out from);
    int.TryParse(Query("count"), out perPage);
    var name = Query("name");
    var content = Query("content");

    var monitor = Storage.GetMonitoringApi();
    var pager = new Pager(from, perPage, GetTotal(monitor));
    var queryDto = new MessageQueryDto
    {
        MessageType = MessageType.Publish,
        Name = name,
        Content = content,
        StatusName = Name,
        CurrentPage = pager.CurrentPage - 1,
        PageSize = pager.RecordsPerPage
    };
    var succeededMessages = monitor.Messages(queryDto);
}

<div class="row">
    <div class="col-md-3">
        @Html.MessagesSidebar(MessageType.Publish)
    </div>
    <div class="col-md-9">
        <h1 class="page-header">@Strings.PublishedPage_Title</h1>

        @if (succeededMessages.Count == 0)
        {
            <div class="alert alert-info">
                @Strings.MessagesPage_NoMessages
            </div>
        }
        else
        {
            <div class="js-jobs-list">
                <div class="btn-toolbar btn-toolbar-top">
                    <form class="row">
                        <div class="col-md-3">
                            <input type="text" class="form-control" name="name" value="@Query("name")" placeholder="@Strings.MessagesPage_Query_MessageName"/>
                        </div>
                        <div class="col-md-5">
                            <div class="input-group">
                                <input type="text" class="form-control" name="content" value="@Query("content")" placeholder="@Strings.MessagesPage_Query_MessageBody"/>
                                <span class="input-group-btn">
                                    <button class="btn btn-info">@Strings.MessagesPage_Query_Button</button>
                                </span>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="btn-toolbar btn-toolbar-top">
                    <button class="js-jobs-list-command btn btn-sm btn-primary"
                            data-url="@Url.To("/published/requeue")"
                            data-loading-text="@Strings.Common_Enqueueing"
                            disabled="disabled">
                        <span class="glyphicon glyphicon-repeat"></span>
                        @Strings.Common_RequeueMessages
                    </button>

                    @Html.PerPageSelector(pager)
                </div>

                <div class="table-responsive">
                    <table class="table">
                        <thead>
                        <tr>
                            <th style="width: 30px;">
                                <input type="checkbox" class="js-jobs-list-select-all"/>
                            </th>
                            <th style="width: 175px">@Strings.Common_Id</th>
                            <th>@Strings.Common_Version</th>
                            <th>@Strings.MessagesPage_Table_Name</th>
                            <th class="min-width">@Strings.MessagesPage_Table_Retries</th>
                            @if (string.Equals(Name, "Processing", StringComparison.CurrentCultureIgnoreCase))
                            {
                                <th>@Strings.MessagesPage_Table_State</th>
                            }
                            <th class="align-right">@Strings.MessagesPage_Table_ExpiresAt</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach (var message in succeededMessages)
                        {
                            <tr class="js-jobs-list-row hover">
                                <td>
                                    <input type="checkbox" class="js-jobs-list-checkbox" name="messages[]" value="@message.Id" />
                                </td>
                                <td class="word-break">
                                    <a href="javascript:;" data-url='@(Url.To("/published/message/") + message.Id)' class="openModal">#@message.Id</a>
                                </td>
                                <td>
                                    @message.Version
                                </td>
                                <td>
                                    @message.Name
                                </td>
                                <td>
                                    @message.Retries
                                </td>
                                @if (string.Equals(Name, "Processing", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    <td>
                                        @message.StatusName
                                    </td>
                                }
                                <td class="align-right">
                                    @if (message.ExpiresAt.HasValue)
                                    {
                                        @Html.RelativeTime(message.ExpiresAt.Value)
                                    }
                                </td>

                            </tr>
                        }
                        </tbody>
                    </table>
                </div>
                @Html.Paginator(pager)
            </div>

            <div>
                <div class="modal fade" tabindex="-1" role="dialog">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                                <h4 class="modal-title">Message Content</h4>
                            </div>
                            <div id="jsonContent" style="max-height: 500px; overflow-y: auto;" class="modal-body">
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-sm btn-primary" id="formatBtn" onclick="">@Strings.MessagesPage_Modal_Format</button>
                                <button type="button" class="btn btn-sm btn-primary" id="rawBtn" onclick="">@Strings.MessagesPage_Modal_Raw</button>
                                <button type="button" class="btn btn-sm btn-primary" id="expandBtn" onclick="">@Strings.MessagesPage_Modal_Expand</button>
                                <button type="button" class="btn btn-sm btn-primary" id="collapseBtn" onclick="">@Strings.MessagesPage_Model_Collaspse</button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div><!-- /.modal -->
            </div>
        }
    </div>
</div>